package com.wangsd.web.api.service;

import com.wangsd.web.mqpay.entity.Trade;
import com.wangsd.web.mqpay.service.CustomerService;
import com.wangsd.web.mqpay.service.TradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class NotifyService {

    @Value("${notify_url}")
    private String notify_url;
    @Autowired
    private CustomerService customerService;
    @Autowired
    private TradeService tradeService;

    @Transactional
    public String noticeAndUpdate(Trade trade, String transactionId) {
        boolean isFlag = false;
        if (trade.getNotifyStatus() == 0) { //未通知
            //通知回调
            isFlag = tradeService.doNotice(trade, transactionId);
            //计算平台收入
            customerService.updateCustomerAmount(trade);
        } else if (trade.getNotifyStatus() == 2) { //通知失败
            //通知回调
            isFlag = tradeService.doNotice(trade, transactionId);
        }
        return isFlag ? "success" : "fail";
    }

}
